package cn.csc.module.product.mq.consumer.stocklock;

import cn.csc.module.pay.message.PayOrderNotifyMessage;
import cn.csc.module.product.service.stocklock.SkuStockLockService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.function.Consumer;

import static cn.csc.framework.common.util.json.JsonUtils.toJsonString;

/**
 * 消费支付订单支付成功消息
 * topic: pay_order_notify_stock
 * Bean的注解名 payOrderNotifyConsumer 与channel的前半段相同(payOrderNotifyConsumer-in-0)
 * {@link PayOrderNotifyMessage}
 * @author liuchuang
 * @version 1.0
 * @date 2024/1/29 16:45
 * @modify
 */
@Slf4j
@Component
public class PayOrderNotifyConsumer implements Consumer<PayOrderNotifyMessage> {

    @Autowired
    private SkuStockLockService skuStockLockService;

    /**
     * 订单支付成功,锁定库存
     *
     * @param message 支付订单支付成功通知消息
     */
    @Override
    public void accept(PayOrderNotifyMessage message) {
        log.info("支付回调开始... message: {}", toJsonString(message));
        // 更新商品订单的支付状态(order_status=2)
        skuStockLockService.markerStockUse(null);
    }
}
